package com.enzoism.springboot.dive.bis.util;



import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.regex.Pattern;

/**
 * 因为最近在看源代码，补充一个删除注释的工具方法
 */
public class CleanCommons {
    private static Pattern pattern = Pattern.compile("/\\*.+?\\*/", Pattern.DOTALL);
    private static final String filePath = "/Users/rong/Desktop/temp";
    public static void main(String[] args) throws IOException {
        Collection<File> java = FileUtils.listFiles(new File(filePath), new String[]{"java"}, true);
        for (File file : java) {
            String content = FileUtils.readFileToString(file, "utf-8");
            FileUtils.writeStringToFile(file, cleanCommons(content), "utf-8");
        }
    }

    public static String cleanCommons(String content) {
        content.replaceAll("//.+\\r\\n", "");
        return pattern.matcher(content).replaceAll("");

    }
}

